fix(threading): Prevent crash during CRT shutdown when unregistering threads - #590
Open
sentry[bot] wants to merge 1 commit into
Open
fix(threading): Prevent crash during CRT shutdown when unregistering threads#590sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses a crash (
EXCEPTION_ACCESS_VIOLATION_READ / 0x0) occurring inUnregister_Thread_IDduring application shutdown.Root Cause:
The global
ThreadList(DynamicVectorClass<ThreadInfoType*>) inExcept.cppis a CRT static object. During application exit, the CRT destroys static/global objects. If worker threads are still active and attempt to callUnregister_Thread_IDafterThreadList's destructor has run (which frees and nulls its internal data array), accessingThreadList[i]results in a null pointer dereference.Solution:
Introduced a
volatile LONG s_crt_shutting_downflag. Anatexit()callback (Mark_CRT_Shutdown) is registered to set this flag to1when CRT shutdown begins.atexithandlers execute before global object destructors, ensuring the flag is set in time.Both
Register_Thread_IDandUnregister_Thread_IDnow checks_crt_shutting_downat their entry point. If the flag is set, they return immediately, preventing any access to theThreadListglobal once CRT shutdown has commenced. This mirrors the approach taken in PR #483 to protect the thread list's critical section.Fixes CLIENT-38C